package com.supermap.localization.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.supermap.localization.commontypes.ExtractConfig;
import com.supermap.localization.commontypes.ReplaceConfig;
import com.supermap.localization.impl.Extracter;

public class ConfigsUtil {
    public static ExtractConfig extractConfig = new ExtractConfig();
    public static ReplaceConfig replaceConfig = new ReplaceConfig();
    public static List<Extracter> extracters = new ArrayList<>();

    public static void initConfig() throws Exception {
        Properties prop = PropertiesHelper.loadProperties(new File("localizationTool.properties").getAbsolutePath());
        // 默认值没有考虑
        extractConfig.setSourceDir(prop.getProperty("sourceDir"));
        extractConfig.setExtractFilePath(prop.getProperty("extract"));
        extractConfig.setExtractInfoFilePath(prop.getProperty("extractInfo"));
        replaceConfig.setSourceDir(prop.getProperty("sourceDir"));
        replaceConfig.setTranslateFilePath(prop.getProperty("translate"));
        replaceConfig.setDestDir(prop.getProperty("destDir"));
        replaceConfig.setSuffix(prop.getProperty("targetSuffix"));
        replaceConfig.setReplaceSuffix(prop.getProperty("replacedSuffix"));
        String extracterRoot = prop.getProperty("extracter.Root");
        String[] extracterRoots = extracterRoot.split(",");
        for (int i = 0; i < extracterRoots.length; i++) {
            Extracter extracter = new Extracter();
            extracter.setAfterExclude(prop.getProperty("extracter." + extracterRoots[i] + ".afterExclude"));
            extracter.setInclude(prop.getProperty("extracter." + extracterRoots[i] + ".include"));
            extracter.setBeforeExclude(prop.getProperty("extracter." + extracterRoots[i] + ".beforeExclude"));
            extracters.add(extracter);
        }
    }
}
